<?php if(!class_exists("View", false)) exit("no direct access allowed");?><main id="main" class="in">
  <div class="container-fluid">
      <div class="row">
          <div class="col-xs-12">
              <div class="panel">
                  <div class="panel-heading">
                      <div class="title">  
                        浏览分组
                        <div class="pull-right">
                          <a style="display:inline;" href="#" class="btn btn-primary groupadd" data-width="550"><i class="icon-plus"></i> 新增分组</a>
                        </div>
                      </div>
                      
                  </div>
                  <div class="panel-body">  
                    <table class="table datatable grouplist">
                      <thead>
                        <tr>
                          <th>ID</th>
                          <th>应用名称</th>
                          <th>分组名称</th>
                          <th>分组描述</th>
                          <th>用户列表</th>
                          <th>操作</th>
                        </tr>
                      </thead>
                      <tbody>
                        <?php if(!empty($groups['data'])){ $_foreach_v_counter = 0; $_foreach_v_total = count($groups['data']);?><?php foreach( $groups['data'] as $k => $v ) : ?><?php $_foreach_v_index = $_foreach_v_counter;$_foreach_v_iteration = $_foreach_v_counter + 1;$_foreach_v_first = ($_foreach_v_counter == 0);$_foreach_v_last = ($_foreach_v_counter == $_foreach_v_total - 1);$_foreach_v_counter++;?>
                        <tr>
                          <td><?php echo htmlspecialchars($v['id'], ENT_QUOTES, "UTF-8"); ?></td>
                          <td><?php echo htmlspecialchars($v['app'], ENT_QUOTES, "UTF-8"); ?></td>
                          <td><?php echo htmlspecialchars($v['name'], ENT_QUOTES, "UTF-8"); ?></td>
                          <td><?php echo htmlspecialchars($v['desc'], ENT_QUOTES, "UTF-8"); ?></td>
                          <td><?php echo htmlspecialchars($v['realname'], ENT_QUOTES, "UTF-8"); ?></td>
                          <td>
                            <!--<a href="<?php echo url(array('c'=>"System", 'a'=>"GroupUser", 'id'=>"", ));?><?php echo htmlspecialchars($v['id'], ENT_QUOTES, "UTF-8"); ?>" title="成员维护" class="with-padding"><i class="icon-common-group icon-group"></i></a>-->
                            <a href="<?php echo url(array('c'=>"System", 'a'=>"GroupPriv", 'id'=>"", ));?><?php echo htmlspecialchars($v['id'], ENT_QUOTES, "UTF-8"); ?>" title="权限维护" class="with-padding"><i class="icon-common-lock icon-lock"></i></a>
                            <a href="#" onclick="del(<?php echo htmlspecialchars($v['id'], ENT_QUOTES, "UTF-8"); ?>)" title="删除分组" class="with-padding"><i class="icon-common-trash icon-trash"></i></a>
                          </td>
                        </tr>
                        <?php endforeach; }?>
                      </tbody>
                    </table>
                    <?php if ($groups['pager']) : ?>
                    <ul id="myPager" class="pager" data-ride="pager" data-link-Creator="?page={page}" data-page="<?php echo htmlspecialchars($groups['pager']['current_page'], ENT_QUOTES, "UTF-8"); ?>" data-rec-total="<?php echo htmlspecialchars($groups['pager']['total_count'], ENT_QUOTES, "UTF-8"); ?>" data-max-nav-count="<?php echo htmlspecialchars($groups['pager']['total_page'], ENT_QUOTES, "UTF-8"); ?>" data-elements="prev_icon,page_of_total_text,next_icon"></ul>                    
                    <?php endif; ?>
                  </div>
              </div>
          </div>
      </div>
  </div>
  <div class="modal fade" id="editModal">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
          <h4 class="modal-title">新增分组</h4>
        </div>
        <div class="modal-body">
          <table align="center" class="table table-borderless"> 
            <tbody>
              <tr>
                <th>选择应用</th>
                <td class="required">
                  <select class="form-control" id="app">
                    <option value="-1">请选择应用</option>
                    <?php if(!empty($apps)){ $_foreach_v_counter = 0; $_foreach_v_total = count($apps);?><?php foreach( $apps as $k => $v ) : ?><?php $_foreach_v_index = $_foreach_v_counter;$_foreach_v_iteration = $_foreach_v_counter + 1;$_foreach_v_first = ($_foreach_v_counter == 0);$_foreach_v_last = ($_foreach_v_counter == $_foreach_v_total - 1);$_foreach_v_counter++;?>
                    <option value="<?php echo htmlspecialchars($v['id'], ENT_QUOTES, "UTF-8"); ?>"><?php echo htmlspecialchars($v['appName'], ENT_QUOTES, "UTF-8"); ?></option>
                    <?php endforeach; }?>
                  </select>
        </td>
              </tr>
              <tr>
              <th>分组名称</th>
              <td class="required"><input type="text" name="name" id="name" value="" class="form-control" autocomplete="off">
      </td>
            </tr>  
            <tr>
              <th>分组描述</th>
              <td><textarea name="desc" id="desc" rows="5" class="form-control"></textarea>
      </td>
            </tr>  
            
          </tbody></table>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default " data-dismiss="modal">关闭</button>
          <button type="button" class="btn btn-primary groupaddbtn">保存</button>
        </div>
      </div>
    </div>
  </div>
  <script src="http://p1.renbenzhihui.com/zui/js/all.js"></script>
        <script src="/i/js/util.js"></script>
        <script src="http://p1.renbenzhihui.com/zui/lib/datatable/zui.datatable.min.js"></script>
        <script> 
          function del(id){
              $.get('<?php echo url(array('c'=>"System", 'a'=>"GroupDel", 'id'=>"", ));?>'+id,function(data){
                data = JSON.parse(data);
                  if(data.code/1 == 1){
                    location.reload();
                  }else{
                    new $.zui.Messager(data.msg, {
                                type: 'danger',
                                icon: 'exclamation-sign',
                                placement: 'center' // 定义显示位置
                            }).show();
                  }
              });
          }     
          $(function(){            
            $('.groupadd').on('click',function(){
              $('#editModal').modal({
                name:'editModal',
                backdrop:true,
                keyboard:true
              })
            });             
            $('.groupaddbtn').on('click',function(){
              var g_name = Utils.paseData($('#name').val());
              var g_desc = Utils.paseData($('#desc').val());
              var g_app = Utils.paseData($('#app').val());
              if(g_name != '' && g_app != ''){
                $.post('<?php echo url(array('c'=>"System", 'a'=>"GroupAdd", ));?>',{name:g_name,desc:g_desc,app:g_app},function(data){
                  data = JSON.parse(data);
                  if(data.code/1 == 1){
                    location.reload();
                  }else{
                    new $.zui.Messager(data.msg, {
                                type: 'danger',
                                icon: 'exclamation-sign',
                                placement: 'center' // 定义显示位置
                            }).show();
                  }
                });
              }else{
                new $.zui.Messager('分组名称为必填项', {
                                type: 'danger',
                                icon: 'exclamation-sign',
                                placement: 'center' // 定义显示位置
                            }).show();
              }
            });
            $('.grouplist').datatable({
              checkable: true,
              sortable: true,
              minFixedLeftWidth: 300
            });
          });
          </script>
</main>